package com.pd.modules.common;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class FileIO
{

	public static List<String> readDataFile(String _filename)
	{
		Scanner scanner = null;
		File file = new File(_filename);
		List<String> readStrings = new ArrayList<String>();
		try
		{
			scanner = new Scanner(file);

			while (scanner.hasNextLine())
			{
				readStrings.add(scanner.nextLine());
			}
		} catch (FileNotFoundException e)
		{
			e.printStackTrace();
		} finally
		{
			if (scanner != null)
			{
				scanner.close();
			}
		}

		return readStrings;
	}

	public static void saveDataFile(String _filename, String[] _data)
	{
		File file = new File(_filename);
		FileWriter fileWriter = null;
		PrintWriter out = null;
		try
		{
			fileWriter = new FileWriter(file);
			out = new PrintWriter(fileWriter);

			for (int i = 0; i < _data.length; i++)
			{
				out.println(_data[i]);
			}
		} catch (IOException e)
		{
			e.printStackTrace();
		} finally
		{

			if (out != null)
			{
				out.close();
			}
		}
	}
}